<!DOCTYPE html>
<html lang="zh">

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>
    
    ES6 变量的解构赋值 - DSRBLOG
    
  </title>
  

  
  
  <link href="atom.xml" rel="alternate" title="DSRBLOG" type="application/atom+xml">
  <link rel="stylesheet" href="asset/css/style.min.css">
  <link rel="stylesheet" href="asset/css/doc.css">
  <script src="asset/app.js"></script>


</head>

<body> <section class="ct-body">
	<div class="container">
		<div class="columns is-variable bd-klmn-columns is-4 is-centered">
			<div class="column is-four-fifths">
				<div class="post-body single-content">
					
					<h1 class="title">
						ES6 变量的解构赋值
					</h1>


					<div class="media">
						
						
						<div class="media-content">
							<div class="content">
								<p>
									<span class="date">2022/07/03 23:53 下午</span>
									

									

									<br />
									<span class="tran-tags">Tags:</span>&nbsp;
									
									<a class="tag is-link is-light">#ES6新特性</a>
									

								</p>
							</div>
						</div>

					</div>
				</div>
				<article class="markdown-body single-content">
					<p>ES6 允许按照一定模式从数组和对象中提取值，对变量进行赋值，这被称为解构赋值</p>
<h2><a id="%E6%95%B0%E7%BB%84%E7%9A%84%E8%A7%A3%E6%9E%84" class="anchor" aria-hidden="true"><span class="octicon octicon-link"></span></a>数组的解构</h2>
<pre class="line-numbers"><code class="language-js">const Team = ['DSRKafuU' , 'DSRLing' ];
let [kafu, ling] = Team;

console.log(kafu); //输出'DSRKafuU'
console.log(ling); //输出'DSRLing'
</code></pre>
<h2><a id="%E5%AF%B9%E8%B1%A1%E7%9A%84%E8%A7%A3%E6%9E%84" class="anchor" aria-hidden="true"><span class="octicon octicon-link"></span></a>对象的解构</h2>
<pre class="line-numbers"><code class="language-js">const kafu = {
    id: 'DSRKafuU',
    r6: function() {
        console.log(&quot;打不过一定是对面开挂&quot;);
    }
}；

console.log(id); //输出'DSRKafuU'
console.log(r6); //输出'console.log('打不过一定是对面开挂')'

r6(); //输出'打不过一定是对面开挂'

let {id, r6} = kafu;
</code></pre>

				</article>
				<div class="comments-wrap">
					<div class="share-comments">
						

						

						
					</div>
				</div><!-- end comments wrap -->
			</div>
		</div><!-- end columns -->
	</div><!-- end container -->
</section>  














<script src="asset/prism.js"></script>









</body>

</html>